package com.changgou.pay.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/*****
 * @Author: 黑马训练营
 * @Description: com.changgou.pay.config
 ****/
@Configuration
public class RabbitMQConfig {

    /****
     * 可以获取配置文件中的指定属性的值
     */
    @Autowired
    private Environment env;

    /****
     * 创建交换机
     */
    @Bean
    public DirectExchange basicExchange(){
        return new DirectExchange(env.getProperty("mq.pay.exchange.order"),true,false);
    }


    /***
     * 创建队列
     */
    @Bean("queueOrder")
    public Queue queueOrder(){
        return new Queue(env.getProperty("mq.pay.queue.order"));
    }

    /***
     * 秒杀支付状态队列创建队列
     */
    @Bean("queueSeckillOrder")
    public Queue queueSeckillOrder(){
        return new Queue("queueSeckillOrder");
    }

    /***
     * 秒杀状态队列绑定交换机
     */
    @Bean
    public Binding basicBindingSeckill(DirectExchange basicExchange,Queue queueSeckillOrder){
        return BindingBuilder.bind(queueSeckillOrder).to(basicExchange).with("queueSeckillOrder");
    }

    /***
     * 队列绑定交换机
     */
    @Bean
    public Binding basicBinding(DirectExchange basicExchange,Queue queueOrder){
        return BindingBuilder.bind(queueOrder).to(basicExchange).with(env.getProperty("mq.pay.routing.key"));
    }
}
